﻿using Super.Admin.Entities;
using Super.Admin.Models.UserOperateLog;

namespace Super.Admin.Mappers
{
    /// <summary>
    /// UserOperateLogMapper 类用于在 UserOperateLogEntity 和 UserOperateLogModel 之间进行转换。
    /// </summary>
    public static class UserOperateLogMapper
    {
        /// <summary>
        /// 将 UserOperateLogEntity 转换为 UserOperateLogBaseModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserOperateLogBaseModel ToBaseModel(this UserOperateLogEntity entity)
        {
            if (entity == null) return null;
            return new UserOperateLogBaseModel
            {
                Id = entity.Id,
                CreateUserId = entity.CreateUserId,
                OperateType = entity.OperateType,
                Message = entity.Message,
                IpAddress = entity.IpAddress,
                OperateTime = entity.OperateTime,
                PermissionKey = entity.PermissionKey,
            };
        }
        /// <summary>
        /// 将 UserOperateLogEntity 转换为 UserOperateLogDetailModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static UserOperateLogDetailModel ToDetailModel(this UserOperateLogEntity entity)
        {
            if (entity == null) return null;
            return new UserOperateLogDetailModel
            {
                Id = entity.Id,
                CreateUserId = entity.CreateUserId,
                OperateType = entity.OperateType,
                Message = entity.Message,
                IpAddress = entity.IpAddress,
                OperateTime = entity.OperateTime,
                PermissionKey = entity.PermissionKey,
                CreateUser = entity.CreateUser.ToBaseModel()
            };
        }
        /// <summary>
        /// 将 UserOperateLogBaseModel 转换为 UserOperateLogEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserOperateLogEntity ToEntity(this UserOperateLogBaseModel model)
        {
            if (model == null) return null;
            return new UserOperateLogEntity
            {
                Id = model.Id,
                CreateUserId = model.CreateUserId,
                OperateType = model.OperateType,
                Message = model.Message,
                IpAddress = model.IpAddress,
                OperateTime = model.OperateTime,
                PermissionKey = model.PermissionKey,
            };
        }
        /// <summary>
        /// 将 UserOperateLogDetailModel 转换为 UserOperateLogEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static UserOperateLogEntity ToEntity(this UserOperateLogDetailModel model)
        {
            if (model == null) return null;
            return new UserOperateLogEntity
            {
                Id = model.Id,
                CreateUserId = model.CreateUserId,
                OperateType = model.OperateType,
                Message = model.Message,
                IpAddress = model.IpAddress,
                OperateTime = model.OperateTime,
                PermissionKey = model.PermissionKey,
            };
        }
        /// <summary>
        /// 将 UserOperateLogEntity 列表转换为 UserOperateLogBaseModel 列表。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserOperateLogBaseModel> ToBaseModels(this IEnumerable<UserOperateLogEntity> entities)
        {
            return entities?.Select(e => e.ToBaseModel()).ToList();
        }
        /// <summary>
        /// 将 UserOperateLogEntity 列表转换为 UserOperateLogDetailModel 列表。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<UserOperateLogDetailModel> ToDetailModels(this IEnumerable<UserOperateLogEntity> entities)
        {
            return entities?.Select(e => e.ToDetailModel()).ToList();
        }
        /// <summary>
        /// 将 UserOperateLogBaseModel 列表转换为 UserOperateLogEntity 列表。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserOperateLogEntity> ToEntities(this IEnumerable<UserOperateLogBaseModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList();
        }
        /// <summary>
        /// 将 UserOperateLogDetailModel 列表转换为 UserOperateLogEntity 列表。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<UserOperateLogEntity> ToEntities(this IEnumerable<UserOperateLogDetailModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList();
        }
    }
}
